<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="动漫名" prop="animeName">
        <el-input
          v-model="queryParams.animeName"
          placeholder="请输入动漫名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫集下标" prop="animeIndex">
        <el-input
          v-model="queryParams.animeIndex"
          placeholder="请输入动漫集下标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫集数" prop="animeCount">
        <el-input
          v-model="queryParams.animeCount"
          placeholder="请输入动漫集数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫路径" prop="animePath">
        <el-input
          v-model="queryParams.animePath"
          placeholder="请输入动漫路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫观看数" prop="animeWatchCount">
        <el-input
          v-model="queryParams.animeWatchCount"
          placeholder="请输入动漫观看数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫评论数" prop="animeCommentsCount">
        <el-input
          v-model="queryParams.animeCommentsCount"
          placeholder="请输入动漫评论数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫点赞数" prop="animeThumbCount">
        <el-input
          v-model="queryParams.animeThumbCount"
          placeholder="请输入动漫点赞数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫收藏数" prop="animeStarCount">
        <el-input
          v-model="queryParams.animeStarCount"
          placeholder="请输入动漫收藏数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫日期" prop="animeDate">
        <el-date-picker clearable
                        v-model="queryParams.animeDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择动漫日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="动漫类型" prop="animeType">
        <el-input
          v-model="queryParams.animeType"
          placeholder="请输入动漫类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫地区" prop="animeArea">
        <el-input
          v-model="queryParams.animeArea"
          placeholder="请输入动漫地区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫对应的视频id" prop="animeVideoid">
        <el-input
          v-model="queryParams.animeVideoid"
          placeholder="请输入动漫对应的视频id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动漫封面" prop="animeCover">
        <el-input
          v-model="queryParams.animeCover"
          placeholder="请输入动漫封面"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:anime:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:anime:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:anime:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:anime:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="animeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="动漫名" align="center" prop="animeName" />
      <el-table-column label="动漫集下标" align="center" prop="animeIndex" />
      <el-table-column label="动漫集数" align="center" prop="animeCount" />
      <el-table-column label="动漫路径" align="center" prop="animePath" />
      <el-table-column label="动漫观看数" align="center" prop="animeWatchCount" />
      <el-table-column label="动漫评论数" align="center" prop="animeCommentsCount" />
      <el-table-column label="动漫点赞数" align="center" prop="animeThumbCount" />
      <el-table-column label="动漫收藏数" align="center" prop="animeStarCount" />
      <el-table-column label="动漫日期" align="center" prop="animeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.animeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="动漫类型" align="center" prop="animeType" />
      <el-table-column label="动漫地区" align="center" prop="animeArea" />
      <el-table-column label="动漫对应的视频id" align="center" prop="animeVideoid" />
      <el-table-column label="动漫封面" align="center" prop="animeCover" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:anime:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:anime:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改动漫对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="动漫名" prop="animeName">
          <el-input v-model="form.animeName" placeholder="请输入动漫名" />
        </el-form-item>
        <el-form-item label="动漫集下标" prop="animeIndex">
          <el-input v-model="form.animeIndex" placeholder="请输入动漫集下标" />
        </el-form-item>
        <el-form-item label="动漫集数" prop="animeCount">
          <el-input v-model="form.animeCount" placeholder="请输入动漫集数" />
        </el-form-item>
        <el-form-item label="动漫路径" prop="animePath">
          <el-input v-model="form.animePath" placeholder="请输入动漫路径" />
        </el-form-item>
        <el-form-item label="动漫观看数" prop="animeWatchCount">
          <el-input v-model="form.animeWatchCount" placeholder="请输入动漫观看数" />
        </el-form-item>
        <el-form-item label="动漫评论数" prop="animeCommentsCount">
          <el-input v-model="form.animeCommentsCount" placeholder="请输入动漫评论数" />
        </el-form-item>
        <el-form-item label="动漫点赞数" prop="animeThumbCount">
          <el-input v-model="form.animeThumbCount" placeholder="请输入动漫点赞数"/>
        </el-form-item>
        <el-form-item label="动漫收藏数" prop="animeStarCount">
          <el-input v-model="form.animeStarCount" placeholder="请输入动漫收藏数"/>
        </el-form-item>
        <el-form-item label="动漫日期" prop="animeDate">
          <el-date-picker clearable
                          v-model="form.animeDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择动漫日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="动漫类型" prop="animeType">
          <el-input v-model="form.animeType" placeholder="请输入动漫类型"/>
        </el-form-item>
        <el-form-item label="动漫地区" prop="animeArea">
          <el-input v-model="form.animeArea" placeholder="请输入动漫地区"/>
        </el-form-item>
        <el-form-item label="动漫对应的视频id" prop="animeVideoid">
          <el-input v-model="form.animeVideoid" placeholder="请输入动漫对应的视频id"/>
        </el-form-item>
        <el-form-item label="动漫封面" prop="animeCover">
          <el-input v-model="form.animeCover" placeholder="请输入动漫封面"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAnime, getAnime, delAnime, addAnime, updateAnime } from "@/api/system/anime";

export default {
  name: "Anime",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 动漫表格数据
      animeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        animeName: null,
        animeIndex: null,
        animeCount: null,
        animePath: null,
        animeWatchCount: null,
        animeCommentsCount: null,
        animeThumbCount: null,
        animeStarCount: null,
        animeDate: null,
        animeType: null,
        animeArea: null,
        animeVideoid: null,
        animeCover: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询动漫列表 */
    getList() {
      this.loading = true;
      listAnime(this.queryParams).then(response => {
        this.animeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        animeName: null,
        animeIndex: null,
        animeCount: null,
        animePath: null,
        animeWatchCount: null,
        animeCommentsCount: null,
        animeThumbCount: null,
        animeStarCount: null,
        animeDate: null,
        animeType: null,
        animeArea: null,
        animeVideoid: null,
        animeCover: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加动漫";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAnime(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改动漫";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAnime(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAnime(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除动漫编号为"' + ids + '"的数据项？').then(function() {
        return delAnime(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/anime/export', {
        ...this.queryParams
      }, `anime_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
